using System.Collections;
using System.Collections.Generic;
using Datas;
using UnityEngine;
using UnityEngine.UI;
public class Shop : MonoBehaviour
{
    // Start is called before the first frame update
    
   public List<Commodity> CommodityList=new List<Commodity>();
   public HerbalList herbalList;

   public GameObject goodsPre;
   public GameObject displaygoods;

   public Button closeBtn;

   public GameObject prompBox;
   public static int SetShopState;
   public enum ShopState
   {
       NoPurchase,
       ShopSuccess,
       Shopfail,
   }
    
    void Awake()
    {
        CreateGoods();
        closeBtn.onClick.AddListener(OncloseBtn);
        
    }

    // Update is called once per frame
    void Update()
    {
        ShowPrompt(SetShopState);
    }


    void CreateGoods()
    {
        for (int i = 0; i < 8; i++)
        {
            int getId = Random.Range(0, herbalList.MedicincCarLists.Count);
            var articlesId=herbalList.MedicincCarLists[getId].HerbalId;
            var money=Random.Range(100,300);
            CommodityList.Add(new Commodity(i,articlesId,money,1));

            var goods = Instantiate(goodsPre, displaygoods.transform);
            goods.GetComponent<Goods>().GetDb(herbalList.MedicincCarLists[getId].HerbalTitle,money.ToString(),herbalList.MedicincCarLists[getId].HerbalImage,articlesId);
        }
    }

    void OncloseBtn()
    {
        GameObject.Find("Panel_EventCardControl(Clone)").GetComponent<EventCardcontrol>().ShowEventCard();
        Destroy(transform.gameObject);
    }


     void ShowPrompt(int type)
    {
        switch (type)
        {
            case (int)ShopState.NoPurchase:
                break;
            case (int)ShopState.ShopSuccess:
                var promp= Instantiate(prompBox,transform);
                promp.GetComponent<PatientDialog>().Prompt("已购买，金钱剩余："+PlayerData.GetMoney());
                SetShopState = (int) ShopState.NoPurchase;
                break;
            case (int)ShopState.Shopfail:
                var promp1= Instantiate(prompBox,transform);
                promp1.GetComponent<PatientDialog>().Prompt("购买失败,金钱剩余："+PlayerData.GetMoney());
                SetShopState = (int) ShopState.NoPurchase;
                break;
        }
       
    }
}
